package cn.wlj.origin.routing;

import cn.wlj.origin.ConnectUtil;
import cn.wlj.origin.Constant;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @ClassName Sender
 * @Description TODO
 * @Author WLJ
 * @Date 2024/1/15 20:46
 * @Version 1.0
 */
public class Sender {
    public static void main(String[] args) throws Exception{
        // 交换机名
        String exchangeName = Constant.Routing.EXCHANGE_NAME;

        // 获取新连接
        Connection connection = ConnectUtil.getConnection();

        // 声明交换机
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT);
        String insertMsg = "新增消息";
        // 发送新增消息
        channel.basicPublish(exchangeName, Constant.Routing.INSERT_ROUTING_KEY, null, insertMsg.getBytes());;
        System.out.println("【" + insertMsg + "】发送成功");
        String updateMsg = "更新消息";
        // 发送更新消息
        channel.basicPublish(exchangeName, Constant.Routing.UPDATE_ROUTING_KEY, null, updateMsg.getBytes());;
        System.out.println("【" + updateMsg + "】发送成功");
        channel.close();
        connection.close();
    }
}
